home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / jockey / handlers / sl_modem.py < prev    next >
Encoding:
Python Source  |  2009-04-07  |  1.9 KB  |  60 lines

  1. # -*- coding: utf-8 -*-
  2. # (c) 2008 Canonical Ltd.
  3. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  4. # License: GPL v2 or later
  5.  
  6. import re, os.path, logging, subprocess
  7.  
  8. from jockey.handlers import Handler
  9.  
  10. # dummy stub for xgettext
  11. def _(x): return x
  12.  
  13. class SlModem(Handler):
  14.     def __init__(self, backend):
  15.         Handler.__init__(self, backend, name=_('Software modem'),
  16.             rationale=_(
  17.                 'This driver enables the usage of many software modems, as '
  18.                 'commonly found in laptops.\n\n'
  19.                 'If this driver is not enabled, you will not be able to use '
  20.                 'your modem.'))
  21.         self.package = 'sl-modem-daemon'
  22.  
  23.         self.modem_re = re.compile('^\s*\d+\s*\[Modem\s*\]')
  24.         self.modem_as_subdevice_re = re.compile('^card [0-9].*[mM]odem')
  25.  
  26.     def available(self):
  27.         '''Check /proc/asound/cards and aplay -l for a "Modem" card.'''
  28.                 
  29.         if Handler.available(self) == False:
  30.             return False
  31.         
  32.         try:
  33.             for l in open('/proc/asound/cards'):
  34.                 if self.modem_re.match(l):
  35.                     return True
  36.         except IOError, e:
  37.             logging.error('could not open /proc/asound/cards: %s' % str(e))
  38.                 
  39.         try:
  40.             aplay = subprocess.Popen(['aplay', '-l'], env={},
  41.                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  42.             (aplay_out, aplay_err) = aplay.communicate()
  43.         except OSError, e:
  44.             logging.error('could not open aplay -l: %s' % str(e))
  45.             return False
  46.  
  47.         if aplay.returncode != 0:
  48.             logging.error('aplay -l failed with %i: %s' % (aplay.returncode,
  49.                 aplay_err))
  50.             return False
  51.  
  52.         for row in aplay_out.splitlines():
  53.             if self.modem_as_subdevice_re.match(row):
  54.                 return True        
  55.         
  56.         return False
  57.  
  58.     def used(self):
  59.         return self.enabled() and os.path.exists('/dev/modem')
  60.